package com.jml.juc.fork;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * @author:jml
 * @date: 2019/5/30 0:33
 * @description：
 */
public class MainTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() / 3,
                ForkJoinPool.defaultForkJoinWorkerThreadFactory, new TTTFork(),
                false);

        WorkFork workFork = new WorkFork();
        workFork.addTask(new ForkJoinTaskBoot1());
        workFork.addTask(new ForkJoinTaskBoot2());
        workFork.addTask(new ForkJoinTaskBoot3());

        for (int i = 0; i < 2; i++) {
            int finalI = i;
            System.out.println("++++++++++++++++++++++++++begin   " + i);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ForkJoinTaskBoot task = new ForkJoinTaskBoot(workFork);
                    ForkJoinTask<Boolean> submit = forkJoinPool.submit(task);
                    try {
                        System.out.println("--------------------------------"+submit.get()+""+finalI);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }

}
